#!/usr/bin/python
# -*- coding: utf-8 -*-


import maya.cmds as mc
import sys
import re
sys.path.append('E:\script\LZ_Tools')
import fixedCtrl as fc
import IKSplineStretch as iss
import softerToClust as sTc
import creatReversJnt as crj
import simpleTools as smt

reload(fc)
reload(iss)
reload(sTc)
reload(crj)
reload(smt)
###-------------------------  window  -------------------------------------------


def LZ_ToolsWindow():
    LZ_Tools = 'LZ_Tools'
    if mc.window(LZ_Tools,ex = True):
        mc.deleteUI(LZ_Tools)
        
    mc.window(LZ_Tools,widthHeight=(200, 400),t='LZ_Tools_v1.01',menuBar = True,rtf=True,s=True)
    
    
    menuBarLayout = mc.menuBarLayout()
    mc.menu( label='File')
    mc.menuItem( label='about',c='LZ_aboat()')
    
    main = mc.rowColumnLayout('main',numberOfColumns=1,cal = (5,'center'),m=True)
    tabs = mc.tabLayout(innerMarginWidth=5, innerMarginHeight=5)
    
    childdren01 = mc.rowColumnLayout('ch_One',numberOfColumns=1,cal = (5,'center'),m=True)

    #mc.setParent('..')
    #mc.setParent('..')
    mc.frameLayout( label='IKSplineStretch', borderStyle='in',cll=True,cl=False)

    textFileld_Layout = mc.rowColumnLayout(numberOfColumns=1,cal = (5,'center'),m=True)
    mc.textFieldButtonGrp('curveName',label='Load IKSpline Curve', text='',buttonLabel='Load Curve',bc='loadCurve()',en=True)
    mc.textFieldButtonGrp('ikHandleInfo',label='Load ikHandle', text='', buttonLabel='Load IkHandle',bc='loadIkHandle()',en=False)
    mc.textFieldGrp('projectionName',label='projectionName', text='')
    mc.intFieldGrp('jointNumber',numberOfFields=1, label='jointNumber',  value1=4)
    mc.radioButtonGrp('buildOption',label='build option ', labelArray2=['curve', 'ikHandle'], numberOfRadioButtons=2,sl=1,on1='radioButtonOption()',of1='radioButtonOption()')
    mc.radioButtonGrp('stretchOption',label='stretch Option ', labelArray2=['scale', 'translate'], numberOfRadioButtons=2,sl=1)

    
    mc.button(l='build',bgc=(0,0.2,0.2),c='iss.createStrectchIk()')

######
    mc.setParent('ch_One')
    
    mc.frameLayout( label='Fixed  Ctrls', borderStyle='in',cll=True)
    mc.textFieldButtonGrp('FixedCtrls',label='load Mesh', text='', buttonLabel='load Mesh',bc='FixedCtrls_loadmesh()',en=True)
    mc.radioButtonGrp('motherType',label='mother Type', labelArray2=['curve', 'mesh'], numberOfRadioButtons=2,sl=2,on1='fixedType()',of1='fixedType()')
    mc.button(l='Execution',bgc=(0,0.2,0.2),c='fc.fixedCtrl()')
    
    mc.rowColumnLayout(numberOfColumns=1,cal = (5,'center'),m=True)
    mc.intSliderGrp('createReversejnt',field=True,w=100, label='Reversejnt position', minValue=1, maxValue=10, fieldMinValue=1, fieldMaxValue=100, value=1)
    mc.button(l='build',w=30,bgc=(0,0.2,0.2),c='crj.createRecerseJnt()')
    mc.textFieldGrp('conneReverseAttr',label='skin Cluter', text='')
    mc.checkBox('all',p='conneReverseAttr',l='All skinCluters')
    mc.button(l='conneReverseAttr',bgc=(0,0.2,0.2),c='crj.conneReverseAttr()')

#####
    mc.setParent('ch_One')
    mc.frameLayout( label='simple Tools', borderStyle='in',cll=True)
    mc.rowColumnLayout(numberOfColumns=3,cal = (5,'center'),m=True)    

    mc.button(l='softToCluster',bgc=(0,0.2,0.2),c='sTc.softerToClu()')
    mc.button(l='polyAverageVertex',bgc=(0,0.2,0.2),c='sTc.polyAverageVertex()')
    mc.button(l='ranameTools',bgc=(0,0.2,0.2),c='renameTools_window()')
    mc.button(l='makeZeroGroup',bgc=(0,0.2,0.2),c='makeZeroGrpWin()')
    mc.button(l='getSkinJnt',bgc=(0,0.2,0.2),c='smt.getSkinJnt()')
#####    
    mc.setParent('ch_One')
    mc.frameLayout( label='Remarks', borderStyle='in',cll=False)
    mc.text(l='')
    

    
#--------------------------------------------------------------------------------------------
    mc.setParent(tabs)

    childdren02 = mc.rowColumnLayout(numberOfColumns=1,cal = (5,'center'),m=True)    
#---------------------------------------------------------------------------------------------

    mc.setParent(tabs)

    childdren03 = mc.rowColumnLayout(numberOfColumns=1,cal = (5,'center'),m=True)  
    
    
    
    mc.setParent('main')
    mc.tabLayout( tabs, edit=True, tabLabel=((childdren01, 'generalTools'), (childdren02, 'rigPartTools'),(childdren03,'ctrl Maker')) )
    mc.showWindow()
    
    
LZ_ToolsWindow()



def LZ_aboat():
    LZ_aboat = 'LZ_aboat'
    if mc.window(LZ_aboat,ex = True):
        mc.deleteUI(LZ_aboat)
       
    mc.window(LZ_aboat,widthHeight=(300, 300),t='LZ_aboat',menuBar = True,rtf=True,s=True)
    aboat_Layout = mc.columnLayout()
    mc.text(l='crate by lizhi')
    mc.text(l='E-mail:guishiye@sina.cn')
    mc.text(l='QQ: 294596787' )
    mc.text(l='Date: 2012/11/26_v1.01')
     


    mc.showWindow(LZ_aboat)

def loadCurve():
    IKSplineCurve=mc.ls(sl=True)[0]
    mc.textFieldButtonGrp('curveName',e=True, text=IKSplineCurve)
    
def loadIkHandle():
    IKSplineHandle=mc.ls(sl=True)[0]
    mc.textFieldButtonGrp('ikHandleInfo',e=True, text=IKSplineHandle)

def FixedCtrls_loadmesh():
    meshname=mc.ls(sl=True)[0]

    mc.textFieldButtonGrp('FixedCtrls',e=True, text=meshname)
    
def radioButtonOption():
    buildOption=mc.radioButtonGrp('buildOption',q=True,sl=True)
    if buildOption==1:
        mc.textFieldButtonGrp('curveName',e=True,en=True)
        mc.textFieldButtonGrp('ikHandleInfo',e=True,en=False)
        mc.intFieldGrp('jointNumber',e=True,en=True)

    if buildOption==2:
        mc.intFieldGrp('jointNumber',e=True,en=False)
        mc.textFieldButtonGrp('ikHandleInfo',e=True,en=True)
        
def fixedType():
    motherTpye=mc.radioButtonGrp('motherType',q=True,sl=2)
    if motherTpye==1:
        mc.textFieldButtonGrp('FixedCtrls',e=True,label='load Curve')
    if motherTpye==2:
        mc.textFieldButtonGrp('FixedCtrls',e=True,label='load Mesh')

#------------------------------------------------------------------------------------------------------------------
 # rename tools  window 

def renameTools_window():
    renameTools_window='renameTools_window'
    if mc.window(renameTools_window,ex = True):
        mc.deleteUI(renameTools_window)
        
    mc.window(renameTools_window,widthHeight=(200, 300),t='renameTools_window',menuBar = True,rtf=True,s=True)
    main = mc.rowColumnLayout('main',numberOfColumns=1,cal = (5,'center'),m=True)
    mc.separator(w=200,style='in')

    mc.button(l='nameField',bgc=(0,0.2,0.2),c='smt.nameFieldWindow()')
    mc.setParent(main)
    mc.separator(w=200,style='in')
    mc.separator(w=200,style='in')
    seconUI=mc.rowColumnLayout('addPrefix',numberOfColumns=2,cal = (5,'center'),m=True)
    
    mc.text(l='  Prefix :')
    mc.textField('addPrefix',text='')
    
    
  
    mc.setParent(main)
    mc.button(l=' add  Prefix  ',bgc=(0,0.2,0.2),c='smt.addPrefixUI()')
    mc.separator(w=200,style='in')
    mc.separator(w=200,style='in')    
    
    thirdUI=mc.rowColumnLayout('addSufix',numberOfColumns=2,cal = (5,'center'),m=True)
    mc.text(l='  Sufix :')
    mc.textField('addSufix',text='')
    
    
    mc.setParent(main)
    mc.button(l=' Sufix  ',bgc=(0,0.2,0.2),c='smt.addSufixUI()')
    mc.separator(w=200,style='in')
    mc.separator(w=200,style='in')
    
    fourthUI=mc.rowColumnLayout('repalcename',numberOfColumns=2,cal = (5,'center'),m=True)
    mc.text(l='replace  name:')
    mc.textField('repalcename',text='')

    
    mc.setParent(main)
    mc.button(l='apply',bgc=(0,0.2,0.2),c='smt.replaceName()')
    mc.separator(w=200,style='in')
    mc.separator(w=200,style='in')
    
    fourthUI02=mc.rowColumnLayout('sequencerepalcename',numberOfColumns=2,cal = (5,'center'),m=True)
    mc.text(l='replace position:')
    mc.intField('sequencerepalcename',minValue=0, maxValue=20, value=0)

    
    mc.setParent(main)
    mc.button(l='apply',bgc=(0,0.2,0.2),c='smt.SequenceRename()')
    mc.separator(w=200,style='in')
    mc.separator(w=200,style='in')
    
    fifthUI=mc.rowColumnLayout('searchReplaceNames',numberOfColumns=2,cal = (5,'center'),m=True)
    mc.text(l='Search for:')
    mc.textField('Searchfor',text='')
    mc.text(l='Replace  With:')
    mc.textField('ReplaceWith',text='')
    mc.setParent(main)
    mc.radioButtonGrp('searchReplaceNames',label='rename option ', labelArray2=['Hierarchy', 'selected'], numberOfRadioButtons=2,sl=2)
    mc.button(l=' Replace  ',bgc=(0,0.2,0.2),c='smt.searchReplaceNamesTool()')

#    mc.intFieldGrp('addPrefix',numberOfFields=1, label='add Prefix ')

    mc.showWindow() 
 
#------------------------------------------------------------------------------------------------------------------------------
def makeZeroGrpWin():
    makeZeroGrpWin='makeZeroGrpWin'
    if mc.window(makeZeroGrpWin,ex = True):
        mc.deleteUI(makeZeroGrpWin)
        
    mc.window(makeZeroGrpWin,widthHeight=(200, 300),t='make Zero Grp Win',menuBar = True,rtf=True,s=True)
    main = mc.rowColumnLayout('main',numberOfColumns=1,cal = (5,'center'),m=True)
    mc.textFieldGrp('makeZeroGrpSuffix',label='Suffix',text='_zero')
    mc.button(label='Suffix',c='smt.makeZeroGrp()')
    mc.showWindow()